<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>浏览器对象模型</title>
		<script>
			// window.navigator查看浏览器的信息(软件、版本、平台等设备信息)
			// window.screen屏幕的相关信息
			
			function openBaidu() {
				// 打开新窗口
				window.open('https://www.baidu.com')
			}
			function toDemo01() {
				/* http://127.0.0.1:8848/web_study/20241028/demo01.html */
				console.log(window.location.protocol)
				// host = hostname + port
				console.log(window.location.hostname) // ip
				console.log(window.location.port) // 端口号
				//  uri: /web_study/20241028/demo01.html
				console.log(window.location.pathname)
				var path = window.location.pathname
				path = '/' + path.split('/')[1] 
						+ '/20241025/demo01.html'
				// 当前窗口跳转
				location.assign(location.protocol 
				+ '//' + location.host + path
				) // 跳转
			}
		</script>
	</head>
	<body>
		<button onclick="openBaidu()">新窗口中打开百度</button>
		<button onclick="window.close()">关闭窗口</button>
		<button onclick="toDemo01()">跳转到上节课的demo01</button>
		<!-- href跳转需要写相对路径 -->
		<button onclick="location.href = '../20241025/demo02.html'">
			跳转到上节课的demo02
		</button>
		<button onclick="window.history.back()">回退</button>
		<button onclick="window.history.forward()">前进</button>
		<button onclick="window.history.go(-2)">后退2个</button>
	</body>
</html>